<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="author" content="常玉西">
		<title>工资计算器angular方法</title>
		<style>
			input {
				width: 200px;
				margin: 10px 0;
				box-shadow: none;
				text-align: right;
				/*-moz-appearance: textfield;*/
			}
			.span {
				display: inline-block;
				margin: 10px 0;
			}
			.num{
				color: darkcyan;
			}
			.num:hover,.number:hover{
				color: red;
			}
			.number{
				color: green;
			}
			
		</style>
	</head>

	<body ng-app="myAPP">
		<div ng-controller="ctrl1">
			<!--工资-->
			总收入额：<input type="number" ng-model="p" /><br />
			<!--养老，医疗，失业，公积金，税前，税，税后-->
			养老金率：<input type="number" ng-model="yanglao" />%<br /> 养老金额：
			<span class="num">{{p*yanglao/100|money}}</span><br /> 医疗费率：
			<input type="number" ng-model="yiliao" />%<br /> 医疗保险：
			<span class="num">{{p/100*yiliao|money}}</span><br /> 失业费率：
			<input type="number" ng-model="shiye" />%<br /> 失业保险：
			<span class="num">{{p/100*shiye|money}}</span><br /> 公积金率：
			<input type="number" ng-model="gongjj" />%<br /> 公积金额：
			<span class="num">{{p/100*gongjj|money}}</span><br /> 税前工资：
			<span class="span number">{{before()|money}}</span><br /> 应纳税额：
			<span class="span number">{{tax()|money}}</span><br />
			<hr /> 实际收入：
			<span class="span number">{{after()|money}}</span>
		</div>

	</body>
	<script src="angular.js"></script>
	<script type="text/javascript">
		//初始化环境
		var app = angular.module("myAPP", []);
		app.controller("ctrl1", function($scope) {
			$scope.p = 0;
			$scope.yanglao = 8;
			$scope.yiliao = 2;
			$scope.shiye = 0.3;
			$scope.gongjj = 8;
			
			$scope.before = function() {
				return this.p * (100 - this.yanglao - this.yiliao - this.shiye - this.gongjj) / 100;
			};
			$scope.tax = function() {

				var income = (1 - (this.yanglao + this.yiliao + this.shiye + this.gongjj) / 100) * this.p - 3500;
				if(income <= 0) {
					tax = 0;
				} else if(income < 1500) {
					tax = income * 0.03;
				} else if(income < 4500) {
					tax = income * 0.1 - 105;
				} else if(income < 9000) {
					tax = income * 0.2 - 555;
				} else if(income < 35000) {
					tax = income * 0.25 - 1005;
				} else if(income < 55000) {
					tax = income * 0.3 - 2775;
				} else if(income < 80000) {
					tax = income * 0.35 - 5505;
				} else {
					tax = income * 0.45 - 13505;
				}
				return tax;

			};
			$scope.after = function(){
				return this.before() - this.tax();
			};
		});
		
		app.filter("money",function(){
			return function(value){
				return value.toFixed(2);
			}
		})
	</script>

</html>